package com.lushuai.jiubeidanci;

import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
import android.widget.VideoView;
import androidx.appcompat.app.AppCompatActivity;

public class VideoPlayerActivity extends AppCompatActivity {
    
    private VideoView videoPlayer;
    private ImageButton btnClose;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_video_player);
        
        // 隐藏状态栏和导航栏
        View decorView = getWindow().getDecorView();
        int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN
                | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
        decorView.setSystemUiVisibility(uiOptions);
        
        videoPlayer = findViewById(R.id.video_player);
        btnClose = findViewById(R.id.btn_close);
        
        // 获取传递过来的视频资源ID
        int videoResId = getIntent().getIntExtra("video_res_id", 0);
        if (videoResId != 0) {
            String videoPath = "android.resource://" + getPackageName() + "/" + videoResId;
            videoPlayer.setVideoURI(Uri.parse(videoPath));
            videoPlayer.start();
        }
        
        // 设置关闭按钮点击事件
        btnClose.setOnClickListener(v -> finish());
        
        // 设置播放完成监听
        videoPlayer.setOnCompletionListener(mp -> finish());
    }
    
    @Override
    protected void onPause() {
        super.onPause();
        if (videoPlayer != null && videoPlayer.isPlaying()) {
            videoPlayer.pause();
        }
    }
    
    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (videoPlayer != null) {
            videoPlayer.stopPlayback();
        }
    }
} 